//
//  CAMineHeaderView.m
//  LNH
//
//  Created by twentylx on 2018/1/19.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAMineHeaderView.h"

@implementation CAMineHeaderView

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params {
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView {
    self.backgroundColor = [UIColor whiteColor];
}

/**
 初始化视图
 */
- (void)lm_createViewForView {
    [self addSubview:self.headImageView];
    [self addSubview:self.logoImageView];
    [self addSubview:self.nameLabel];
    
    [self addSubview:self.myOrderView];
    [self.myOrderView addSubview:self.myOrderLabel];
    [self.myOrderView addSubview:self.myOrderMoreImageView];
    [self addSubview:self.lineView];
    [self addSubview:self.buttonView];
    [self.buttonView addSubview:self.payBtn];
    [self.buttonView addSubview:self.waitBtn];
    [self.buttonView addSubview:self.collectBtn];
    [self.buttonView addSubview:self.afterBtn];
    
    [self setNeedsUpdateConstraints];
}

#pragma mark layout
- (void) updateConstraints {
    [super updateConstraints];
    
    [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self);
    }];
    
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.headImageView);
//        make.top.equalTo(self).offset(30);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.logoImageView);
        make.top.equalTo(self.logoImageView.mas_bottom).offset(5);
    }];
    
    [self.myOrderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self.headImageView.mas_bottom);
        make.height.mas_equalTo(44);
    }];
    
    [self.myOrderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.myOrderView).offset(20);
        make.centerY.equalTo(self.myOrderView);
    }];
    
    [self.myOrderMoreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.myOrderView.mas_right).offset(-20);
        make.centerY.equalTo(self.myOrderView);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self.myOrderView.mas_bottom);
        make.height.mas_equalTo(1);
    }];
    
    [_buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self.lineView.mas_bottom);
        make.height.mas_equalTo(80);
    }];
    
    [_payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buttonView);
        make.centerY.equalTo(self.buttonView);
        make.width.mas_equalTo(@(SCREEN_WIDTH/4));
        make.height.mas_equalTo(60);
    }];
    
    [_waitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.payBtn.mas_right);
        make.centerY.equalTo(self.buttonView);
        make.width.mas_equalTo(@(SCREEN_WIDTH/4));
        make.height.mas_equalTo(60);
    }];
    
    [_collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.waitBtn.mas_right);
        make.centerY.equalTo(self.buttonView);
        make.width.mas_equalTo(@(SCREEN_WIDTH/4));
        make.height.mas_equalTo(60);
    }];
    
    [_afterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.collectBtn.mas_right);
        make.centerY.equalTo(self.buttonView);
        make.width.mas_equalTo(@(SCREEN_WIDTH/4));
        make.height.mas_equalTo(60);
    }];
}

#pragma mark get & set
- (UIImageView *) headImageView {
    if (!_headImageView) {
        _headImageView = [UIImageView new];
        if (isIPhoneX) {
            _headImageView.image = [UIImage imageNamed:@"header_iphonex"];
        } else {
            _headImageView.image = [UIImage imageNamed:@"header"];
        }
        _headImageView.userInteractionEnabled = YES;
    }
    return _headImageView;
}

- (UIImageView *) logoImageView {
    if (!_logoImageView) {
        _logoImageView = [UIImageView new];
        _logoImageView.layer.masksToBounds =YES;
        _logoImageView.layer.cornerRadius =50;
        _logoImageView.userInteractionEnabled = YES;
        _logoImageView.image = LMImageNamed(@"qrcode_logo");
    }
    return _logoImageView;
}

- (UILabel *) nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.text = @"";
        _nameLabel.font = [UIFont systemFontOfSize:16];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.textColor = [UIColor whiteColor];
    }
    return _nameLabel;
}

/*我的订单*/
- (UIView *) myOrderView {
    if (!_myOrderView) {
        _myOrderView = [UIView new];
        _myOrderView.backgroundColor = [UIColor whiteColor];
        _myOrderView.userInteractionEnabled = YES;
    }
    return _myOrderView;
}

- (UILabel *) myOrderLabel {
    if (!_myOrderLabel) {
        _myOrderLabel = [UILabel new];
        _myOrderLabel.font = [UIFont systemFontOfSize:14];
        _myOrderLabel.text = @"全部订单";
    }
    return _myOrderLabel;
}

- (UIImageView *) myOrderMoreImageView {
    if (!_myOrderMoreImageView) {
        _myOrderMoreImageView = [UIImageView new];
        _myOrderMoreImageView.image = [UIImage imageNamed:@"more"];
    }
    return _myOrderMoreImageView;
}

- (UIView *) lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = RGBCOLOR(241, 241, 241);
    }
    return _lineView;
}

- (UIView *) buttonView {
    if (!_buttonView) {
        _buttonView = [UIView new];
        _buttonView.backgroundColor = [UIColor whiteColor];
    }
    return _buttonView;
}

-(UIButton *)payBtn
{
    if (!_payBtn) {
        _payBtn = [UIButton new];
        [_payBtn setTitle:@"待审核" forState:UIControlStateNormal];
        [_payBtn setTitleColor:RGBCOLOR(62, 58, 57) forState:UIControlStateNormal];
        _payBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_payBtn setImage:[UIImage imageNamed:@"dd_dsh"] forState:UIControlStateNormal];
        if (isIPhonePlus) {
            _payBtn.imageEdgeInsets = UIEdgeInsetsMake(-20, 25, 0,0);
            _payBtn.titleEdgeInsets = UIEdgeInsetsMake(30, -45, 0, 0);
        } else {
            _payBtn.imageEdgeInsets = UIEdgeInsetsMake(-20, 23, 0,0);
            _payBtn.titleEdgeInsets = UIEdgeInsetsMake(30, -25, 0, 0);
        }
        
    }
    return _payBtn;
}

-(UIButton *)waitBtn
{
    if (!_waitBtn) {
        _waitBtn = [UIButton new];
        [_waitBtn setTitle:@"待发货" forState:UIControlStateNormal];
        [_waitBtn setTitleColor:RGBCOLOR(62, 58, 57) forState:UIControlStateNormal];
        _waitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_waitBtn setImage:[UIImage imageNamed:@"dd_dfh"] forState:UIControlStateNormal];
        if (isIPhonePlus) {
            _waitBtn.imageEdgeInsets = UIEdgeInsetsMake(-20, 25, 0,0);
            _waitBtn.titleEdgeInsets = UIEdgeInsetsMake(30, -45, 0, 0);
        } else {
            _waitBtn.imageEdgeInsets = UIEdgeInsetsMake(-20, 23, 0,0);
            _waitBtn.titleEdgeInsets = UIEdgeInsetsMake(30, -25, 0, 0);
        }
    }
    return _waitBtn;
}

-(UIButton *)collectBtn
{
    if (!_collectBtn) {
        _collectBtn = [UIButton new];
        [_collectBtn setTitle:@"待收货" forState:UIControlStateNormal];
        [_collectBtn setTitleColor:RGBCOLOR(62, 58, 57) forState:UIControlStateNormal];
        _collectBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_collectBtn setImage:[UIImage imageNamed:@"dd_dsh"] forState:UIControlStateNormal];
        if (isIPhonePlus) {
            _collectBtn.imageEdgeInsets = UIEdgeInsetsMake(-20, 22, 0,0);
            _collectBtn.titleEdgeInsets = UIEdgeInsetsMake(30, -45, 0, 0);
        } else {
            _collectBtn.imageEdgeInsets = UIEdgeInsetsMake(-20, 23, 0,0);
            _collectBtn.titleEdgeInsets = UIEdgeInsetsMake(30, -25, 0, 0);
        }
    }
    return _collectBtn;
}

-(UIButton *)afterBtn
{
    if (!_afterBtn) {
        _afterBtn = [UIButton new];
        [_afterBtn setTitle:@"售 后" forState:UIControlStateNormal];
        [_afterBtn setTitleColor:RGBCOLOR(62, 58, 57) forState:UIControlStateNormal];
        _afterBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_afterBtn setImage:[UIImage imageNamed:@"dd_sh"] forState:UIControlStateNormal];
        _afterBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        if (isIPhonePlus) {
            _afterBtn.imageEdgeInsets = UIEdgeInsetsMake(-20, 25, 0,0);
            _afterBtn.titleEdgeInsets = UIEdgeInsetsMake(30, -30, 0, 0);
        } else {
            _afterBtn.imageEdgeInsets = UIEdgeInsetsMake(-20, 30, 0,0);
            _afterBtn.titleEdgeInsets = UIEdgeInsetsMake(30, -25, 0, 0);
        }
    }
    return _afterBtn;
}

@end
